<?php
define('debug',0);
$name ='fnsoxt';
$pass = 'zzjfish';

$f = new SaeFetchurl();
list($a,$b) = explode(' ',microtime());
$time =$b.floor($a*1000);
$url = "http://login.xunlei.com/check?u={$name}&cachetime={$time}";
logs($url);
$ret = $f->fetch($url);
logs($ret);
if ($ret === false){
    logs($f->errno());
    logs($f->errmsg());
}
$cookies = $f->responseCookies(false);
$check_result = $cookies['check_result'];
$captcha = array_pop(explode(":",$check_result));
$p = md5(md5(md5($pass)).$captcha);
list($a,$b) = explode(' ',microtime());
$time =$b.floor($a*1000);
$request = "http://dyact.vip.xunlei.com/script/login.php?cachetime={$time}&callback=jsonpvip&u={$name}&p={$p}&verifycode={$captcha}";
logs($request);
// $f->setCookies($f->responseCookies());
$f->setCookies($cookies);
$ret =$f->fetch($request);
if ($ret === false){
    logs($f->errno());
    logs($f->errmsg());
}
logs($ret);
// logs($f->responseCookies());
// logs($f->responseHeaders());
list($a,$b) = explode(' ',microtime());
$time =$b.floor($a*1000);
$f->setCookies($f->responseCookies(false));
$url = "http://dynamic.vip.xunlei.com/sign/daily/?cachetime={$time}";
logs($url);
$ret = $f->fetch($url);
if ($ret === false){
    logs($f->errno());
    logs($f->errmsg());
}
preg_match('#积分为(.*?)分#iU',strip_tags($ret),$code);
if($code[1])
    echo date('Y-m-d')."\t".$code[1]."\tdone.\n";
else
    logs($ret);

function logs($msg){
    if(debug)
        var_dump($msg);
}
